using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;//添加NuGet引用sqlclient
using static System.ComponentModel.Design.ObjectSelectorEditor;
using System.Diagnostics;

namespace DataGridView3_连接数据库3
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            string connectionString = "Data Source=SAN-PC\\WINCCPLUSMIG2014;User ID=sa;Password=sa;Initial Catalog=S7netClass";//"你的连接字符串";
            string sql = "SELECT * FROM 你的数据表";
            //SELECT column1, column2, column3, ... FROM TaskList;
            //  将 column1, column2, column3, ... 替换为除了 Excute 之外的实际列名。
            
            //SELECT Excute AS IsExecuted 用别名替代
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                    {
                        DataTable dataTable = new DataTable();
                        adapter.Fill(dataTable);
                        dataGridView1.DataSource = dataTable;
                    }
                }
            }
        }

    }
}
